import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';

@Index('unique_vote', ['userId', 'candidateId', 'electionSettingId'], {
  unique: true,
})
@Index('candidate_id', ['candidateId'], {})
@Index('election_setting_id', ['electionSettingId'], {})
@Entity('votes', { schema: 'vote' })
export class Votes {
  @PrimaryGeneratedColumn({ type: 'int', name: 'id' })
  id: number;

  @Column('int', { name: 'user_id', comment: '用户ID' })
  userId: number;

  @Column('int', { name: 'candidate_id', comment: '候选人ID' })
  candidateId: number;

  @Column('int', { name: 'election_setting_id', comment: '选举场次' })
  electionSettingId: number;

  @Column('int', {
    name: 'voted_at',
    comment: '投票时间',
    default: () => "'0'",
  })
  votedAt: number;
}
